package com.haidechizi.leetcode;

/**
 * @author: wangdejun
 * @create: 2020-04-02 12:12
 **/
public class _15_二进制中1的个数 {

    public int hammingWeight(int n) {
        int count = 0;
        while (n!= 0) {
            count++;
            n = n & n-1;
        }
        return count;
    }


    public int hammingWeight1(int n) {
        return Integer.bitCount(n);
    }
}
